package com.newtouch.bxzs.database.synchronize.batch.reader;

import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.em.PublishStatusEnum;
import com.newtouch.bxzs.common.base.em.SystemParamsEnum;
import com.newtouch.bxzs.common.base.model.*;
import com.newtouch.bxzs.common.base.util.RedisUtils;
import com.newtouch.bxzs.database.synchronize.mapper.BatchMapper;
import com.newtouch.bxzs.database.synchronize.model.AdvertisementBO;
import org.springframework.batch.item.ItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * 读取本地数据
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/2 14:34</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class ReaderLocalData {

    @Autowired
    private BatchMapper batchMapper;

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 获取待撤销的广告信息
     * @return ItemReader
     */
    public ItemReader<AdvertisementBO> getRevokeAdvertisement() {
        return new ItemReaderFactory<>(batchMapper.getRevokeAdvertisement());
    }

    /**
     * 获取待发布的广告信息
     */
    public ItemReader<AdvertisementBO> getPublishAdvertisement(){
        return new ItemReaderFactory<>(batchMapper.getPublishAdvertisement());
    }

    /**
     * 获取待发布/撤销的产品信息
     */
    public ItemReader<Product> getProductList(){
        return new ItemReaderFactory<>(batchMapper.getProduct());
    }

    /**
     * 获取待发布撤销的通知信息
     */
    public ItemReader<Notification> getNotificationList(){
        return new ItemReaderFactory<>(batchMapper.getNotification());
    }

    /**
     * 获取待发布撤销的知识小灵通
     */
    public ItemReader<KnowledgeCard> getKnowledgeCardList(){
        return new ItemReaderFactory<>(batchMapper.getKnowledgeCard());
    }

    /**
     * 获取待发布撤销的知识库
     */
    public ItemReader<KnowledgeBase> getKnowledgeBaseList(){
        return new ItemReaderFactory<>(batchMapper.getKnowledgeBase());
    }

    /**
     * 提醒升级
     */
    public ItemReader<User> getRemindToUpgrade(){
        String result = redisUtils.get(SystemParamsEnum.REMIND_TO_UPGRADE.getCode());
        if (StringUtils.isEmpty(result)){
            throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL);
        }
        return new ItemReaderFactory<>(batchMapper.getRemindToUpgrade(result));
    }

    /**
     * 获取应该结束的营销活动
     */
    public ItemReader<Activity>getMarketingActivity(){
        return new ItemReaderFactory<>(batchMapper.getMarketingActivity(PublishStatusEnum.PUBLISHED_STATUS.getResultCode()));
    }

    /**
     * 获取应该结束的营销会议
     */
    public ItemReader<Conference>getMarketingConference(){
        return new ItemReaderFactory<>(batchMapper.getMarketingConference(PublishStatusEnum.PUBLISHED_STATUS.getResultCode()));
    }

    /**
     *获取待发布和撤销的课程信息
     */
    public ItemReader<Course> getCourseList(){
        return new ItemReaderFactory<>(batchMapper.getCourse());
    }

    /**
     *获取待发布和撤销的考试信息
     */
    public ItemReader<Examination> getExamination(){
        return new ItemReaderFactory<>(batchMapper.getExamination());
    }
}
